﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace PJ.Data
{
    [Serializable]
    [DataContract]
    public abstract class BaseObjectData : IObjectData
    {
        private string m_GlobalID;
        private DateTime? m_CachedDate;


        [DataMember]
        public DateTime? CachedDate
        {
            get { return m_CachedDate; }
            set { m_CachedDate = value; }
        }

        [DataMember]
        public string GlobalId
        {
            get
            {
                return m_GlobalID;
            }
            set
            {
                m_GlobalID = value;
            }
        }
        protected BaseObjectData()
        {
        }

        public virtual IObjectData Init(IObjectData data)
        {
            if (data == null)
                throw new ArgumentNullException("data");
            this.CachedDate = data.CachedDate;
            this.GlobalId = data.GlobalId;
            return Copy(data);
        }

        public virtual IObjectData Copy(IObjectData data)
        {
            if (data == null)
                throw new ArgumentNullException("data");
            return this;
        }

        /// <summary>
        /// IsEqual : Checks id ObjectData properties are the same
        /// </summary>
        /// <param name="data">Data Object to compare</param>
        /// <returns>true if is equal else false</returns>
        public virtual bool IsEqual(IObjectData data)
        {
            if (data == null)
                throw new ArgumentNullException("data");
            if (this.GlobalId == data.GlobalId)
                return true;
            return false;
        }
        public virtual string Error
        {
            get { return null; }
        }

        public virtual string this[string columnName]
        {
            get { return null; }
        }

        public IObjectData Clone()
        {
            return CreateNewInstance().Init(this);
        }

        public abstract IObjectData CreateNewInstance();

    }
}
